package com.san.base.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.san.base.dao.CodeDao;
import com.san.base.domain.CodeDO;
import com.san.base.service.CodeService;
import com.san.base.vo.CodeVO;

@Service
public class CodeServiceImpl implements CodeService {
	
	@Autowired
	private CodeDao dao;

	@Override
	public CodeDO getById(Long id) {		
		return dao.getById(id);
	}
	
	@Override
	public CodeDO getByName(String codeName) {
		return dao.getByName(codeName);
	}


	@Override
	public List<CodeDO> list(Map<String, Object> map) {
		return dao.list(map);
	}

	@Override
	public int count(Map<String, Object> map) {
		return dao.count(map);
	}

	@Override
	public int save(CodeVO code) {
		//判断该系统编码名称是否已经存在
		String codeName = code.getCodeName();
		CodeDO code1 = getByName(codeName);
		if(code1 != null){
			return -1;
		}else{
			return dao.save(code);
		}
	}

	@Override
	public int doEdit(CodeVO code) {
		//判断该系统编码名称是否已经存在
		String codeName = code.getCodeName();
		String oldName = code.getOldName();
		CodeDO code1 = getByName(codeName);
		if(!codeName.equals(oldName) && code1 != null){
			return -1;
		}else{
			return dao.doEdit(code);
		}
	}

	@Override
	public int remove(Long id) {
		return dao.remove(id);
	}

	@Override
	public int batchRemove(Long[] ids) {
		return dao.batchRemove(ids);
	}

	
}
